package com.cwx.mychat.mappers;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cwx.mychat.entity.po.GroupInfo;
import com.cwx.mychat.entity.po.UserContact;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserContactMapper extends BaseMapper<UserContact> {
    /**
     * 查询我的好友
     * @param userId
     * @return
     */
    List<UserContact> selectContactList(@Param("userId") String userId);

    /**
     * 查询单个好友
     * @param userId
     * @param contactId
     * @return
     */
    default UserContact selectOne(String userId, String contactId) {
        return selectOne(new LambdaQueryWrapper<UserContact>()
                .eq(UserContact::getUserId, userId)
                .eq(UserContact::getContactId, contactId)
                .or()
                .eq(UserContact::getContactId, userId)
                .eq(UserContact::getUserId, contactId));
    }
    /**
     * 查询群聊成员
     * @param groupId 群组Id
     * @return
     */
    List<UserContact> selectContactListByGroupId(@Param("groupId") String groupId);

    /**
     * 通过userId查询所有有联系的群组信息
     * @param userId
     * @return
     */
    List<UserContact> selectAllGroupByUserId(@Param("userId") String userId);
}
